home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / containers / ViewStack.as < prev   
Encoding:
Text File  |  2008-11-25  |  18.7 KB  |  618 lines

  1. package mx.containers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.Event;
  5.    import mx.automation.IAutomationObject;
  6.    import mx.core.Container;
  7.    import mx.core.ContainerCreationPolicy;
  8.    import mx.core.EdgeMetrics;
  9.    import mx.core.IInvalidating;
  10.    import mx.core.IUIComponent;
  11.    import mx.core.ScrollPolicy;
  12.    import mx.core.UIComponent;
  13.    import mx.core.mx_internal;
  14.    import mx.effects.Effect;
  15.    import mx.effects.EffectManager;
  16.    import mx.events.ChildExistenceChangedEvent;
  17.    import mx.events.EffectEvent;
  18.    import mx.events.FlexEvent;
  19.    import mx.events.IndexChangedEvent;
  20.    import mx.graphics.RoundedRectangle;
  21.    import mx.managers.HistoryManager;
  22.    import mx.managers.IHistoryManagerClient;
  23.    
  24.    use namespace mx_internal;
  25.    
  26.    public class ViewStack extends Container implements IHistoryManagerClient
  27.    {
  28.       mx_internal static const VERSION:String = "3.2.0.3958";
  29.       
  30.       private var dispatchChangeEventPending:Boolean = false;
  31.       
  32.       private var historyManagementEnabledChanged:Boolean = false;
  33.       
  34.       mx_internal var vsPreferredHeight:Number;
  35.       
  36.       private var initialSelectedIndex:int = -1;
  37.       
  38.       private var firstTime:Boolean = true;
  39.       
  40.       mx_internal var _historyManagementEnabled:Boolean = false;
  41.       
  42.       private var overlayChild:Container;
  43.       
  44.       private var overlayTargetArea:RoundedRectangle;
  45.       
  46.       private var proposedSelectedIndex:int = -1;
  47.       
  48.       private var needToInstantiateSelectedChild:Boolean = false;
  49.       
  50.       private var bSaveState:Boolean = false;
  51.       
  52.       mx_internal var vsMinHeight:Number;
  53.       
  54.       private var bInLoadState:Boolean = false;
  55.       
  56.       mx_internal var vsPreferredWidth:Number;
  57.       
  58.       private var _resizeToContent:Boolean = false;
  59.       
  60.       mx_internal var vsMinWidth:Number;
  61.       
  62.       private var lastIndex:int = -1;
  63.       
  64.       private var _selectedIndex:int = -1;
  65.       
  66.       public function ViewStack()
  67.       {
  68.          super();
  69.          addEventListener(ChildExistenceChangedEvent.CHILD_ADD,childAddHandler);
  70.          addEventListener(ChildExistenceChangedEvent.CHILD_REMOVE,childRemoveHandler);
  71.       }
  72.       
  73.       protected function get contentHeight() : Number
  74.       {
  75.          var _loc1_:EdgeMetrics = viewMetricsAndPadding;
  76.          return unscaledHeight - _loc1_.top - _loc1_.bottom;
  77.       }
  78.       
  79.       public function set selectedChild(param1:Container) : void
  80.       {
  81.          var _loc2_:int = getChildIndex(DisplayObject(param1));
  82.          if(_loc2_ >= 0 && _loc2_ < numChildren)
  83.          {
  84.             selectedIndex = _loc2_;
  85.          }
  86.       }
  87.       
  88.       override mx_internal function setActualCreationPolicies(param1:String) : void
  89.       {
  90.          var _loc2_:int = 0;
  91.          var _loc3_:Container = null;
  92.          super.mx_internal::setActualCreationPolicies(param1);
  93.          if(param1 == ContainerCreationPolicy.ALL && numChildren > 0)
  94.          {
  95.             _loc2_ = 0;
  96.             while(_loc2_ < numChildren)
  97.             {
  98.                _loc3_ = getChildAt(_loc2_) as Container;
  99.                if(Boolean(_loc3_) && _loc3_.mx_internal::numChildrenCreated == -1)
  100.                {
  101.                   _loc3_.createComponentsFromDescriptors();
  102.                }
  103.                _loc2_++;
  104.             }
  105.          }
  106.       }
  107.       
  108.       private function dispatchChangeEvent(param1:int, param2:int) : void
  109.       {
  110.          var _loc3_:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHANGE);
  111.          _loc3_.oldIndex = param1;
  112.          _loc3_.newIndex = param2;
  113.          _loc3_.relatedObject = getChildAt(param2);
  114.          dispatchEvent(_loc3_);
  115.       }
  116.       
  117.       protected function get contentY() : Number
  118.       {
  119.          return getStyle("paddingTop");
  120.       }
  121.       
  122.       protected function commitSelectedIndex(param1:int) : void
  123.       {
  124.          var _loc3_:Container = null;
  125.          var _loc4_:Effect = null;
  126.          if(numChildren == 0)
  127.          {
  128.             _selectedIndex = -1;
  129.             return;
  130.          }
  131.          if(param1 < 0)
  132.          {
  133.             param1 = 0;
  134.          }
  135.          else if(param1 > numChildren - 1)
  136.          {
  137.             param1 = numChildren - 1;
  138.          }
  139.          if(lastIndex != -1 && lastIndex < numChildren)
  140.          {
  141.             Container(getChildAt(lastIndex)).endEffectsStarted();
  142.          }
  143.          if(_selectedIndex != -1)
  144.          {
  145.             selectedChild.endEffectsStarted();
  146.          }
  147.          lastIndex = _selectedIndex;
  148.          if(param1 == lastIndex)
  149.          {
  150.             return;
  151.          }
  152.          _selectedIndex = param1;
  153.          if(initialSelectedIndex == -1)
  154.          {
  155.             initialSelectedIndex = _selectedIndex;
  156.          }
  157.          if(lastIndex != -1 && param1 != -1)
  158.          {
  159.             dispatchChangeEventPending = true;
  160.          }
  161.          var _loc2_:Boolean = false;
  162.          if(lastIndex != -1 && lastIndex < numChildren)
  163.          {
  164.             _loc3_ = Container(getChildAt(lastIndex));
  165.             _loc3_.setVisible(false);
  166.             if(_loc3_.getStyle("hideEffect"))
  167.             {
  168.                _loc4_ = EffectManager.mx_internal::lastEffectCreated;
  169.                if(_loc4_)
  170.                {
  171.                   _loc4_.addEventListener(EffectEvent.EFFECT_END,hideEffectEndHandler);
  172.                   _loc2_ = true;
  173.                }
  174.             }
  175.          }
  176.          if(!_loc2_)
  177.          {
  178.             hideEffectEndHandler(null);
  179.          }
  180.       }
  181.       
  182.       private function instantiateSelectedChild() : void
  183.       {
  184.          if(!selectedChild)
  185.          {
  186.             return;
  187.          }
  188.          if(Boolean(selectedChild) && selectedChild.mx_internal::numChildrenCreated == -1)
  189.          {
  190.             if(initialized)
  191.             {
  192.                selectedChild.addEventListener(FlexEvent.CREATION_COMPLETE,childCreationCompleteHandler);
  193.             }
  194.             selectedChild.createComponentsFromDescriptors(true);
  195.          }
  196.          if(selectedChild is IInvalidating)
  197.          {
  198.             IInvalidating(selectedChild).invalidateSize();
  199.          }
  200.          invalidateSize();
  201.          invalidateDisplayList();
  202.       }
  203.       
  204.       private function initializeHandler(param1:FlexEvent) : void
  205.       {
  206.          overlayChild.removeEventListener(FlexEvent.INITIALIZE,initializeHandler);
  207.          UIComponent(overlayChild).mx_internal::addOverlay(mx_internal::overlayColor,overlayTargetArea);
  208.       }
  209.       
  210.       public function set historyManagementEnabled(param1:Boolean) : void
  211.       {
  212.          if(param1 != mx_internal::_historyManagementEnabled)
  213.          {
  214.             mx_internal::_historyManagementEnabled = param1;
  215.             historyManagementEnabledChanged = true;
  216.             invalidateProperties();
  217.          }
  218.       }
  219.       
  220.       override public function get horizontalScrollPolicy() : String
  221.       {
  222.          return ScrollPolicy.OFF;
  223.       }
  224.       
  225.       private function childAddHandler(param1:ChildExistenceChangedEvent) : void
  226.       {
  227.          var _loc4_:IUIComponent = null;
  228.          var _loc2_:DisplayObject = param1.relatedObject;
  229.          var _loc3_:int = getChildIndex(_loc2_);
  230.          if(_loc2_ is IUIComponent)
  231.          {
  232.             _loc4_ = IUIComponent(_loc2_);
  233.             _loc4_.visible = false;
  234.          }
  235.          if(numChildren == 1 && proposedSelectedIndex == -1)
  236.          {
  237.             proposedSelectedIndex = 0;
  238.             invalidateProperties();
  239.          }
  240.          else if(_loc3_ <= _selectedIndex && numChildren > 1)
  241.          {
  242.             ++selectedIndex;
  243.          }
  244.          if(!(_loc2_ as IAutomationObject))
  245.          {
  246.          }
  247.          IAutomationObject(_loc2_).showInAutomationHierarchy = true;
  248.       }
  249.       
  250.       private function addedToStageHandler(param1:Event) : void
  251.       {
  252.          if(historyManagementEnabled)
  253.          {
  254.             HistoryManager.register(this);
  255.          }
  256.       }
  257.       
  258.       public function get resizeToContent() : Boolean
  259.       {
  260.          return _resizeToContent;
  261.       }
  262.       
  263.       public function saveState() : Object
  264.       {
  265.          var _loc1_:int = _selectedIndex == -1 ? 0 : _selectedIndex;
  266.          return {"selectedIndex":_loc1_};
  267.       }
  268.       
  269.       override public function get autoLayout() : Boolean
  270.       {
  271.          return true;
  272.       }
  273.       
  274.       override mx_internal function removeOverlay() : void
  275.       {
  276.          if(overlayChild)
  277.          {
  278.             UIComponent(overlayChild).mx_internal::removeOverlay();
  279.             overlayChild = null;
  280.          }
  281.       }
  282.       
  283.       private function removedFromStageHandler(param1:Event) : void
  284.       {
  285.          HistoryManager.unregister(this);
  286.       }
  287.       
  288.       [Bindable("valueCommit")]
  289.       public function get selectedChild() : Container
  290.       {
  291.          if(selectedIndex == -1)
  292.          {
  293.             return null;
  294.          }
  295.          return Container(getChildAt(selectedIndex));
  296.       }
  297.       
  298.       private function hideEffectEndHandler(param1:EffectEvent) : void
  299.       {
  300.          if(param1)
  301.          {
  302.             param1.currentTarget.removeEventListener(EffectEvent.EFFECT_END,hideEffectEndHandler);
  303.          }
  304.          needToInstantiateSelectedChild = true;
  305.          invalidateProperties();
  306.          if(bSaveState)
  307.          {
  308.             HistoryManager.save();
  309.             bSaveState = false;
  310.          }
  311.       }
  312.       
  313.       private function childCreationCompleteHandler(param1:FlexEvent) : void
  314.       {
  315.          param1.target.removeEventListener(FlexEvent.CREATION_COMPLETE,childCreationCompleteHandler);
  316.          param1.target.dispatchEvent(new FlexEvent(FlexEvent.SHOW));
  317.       }
  318.       
  319.       override public function set horizontalScrollPolicy(param1:String) : void
  320.       {
  321.       }
  322.       
  323.       public function get historyManagementEnabled() : Boolean
  324.       {
  325.          return mx_internal::_historyManagementEnabled;
  326.       }
  327.       
  328.       public function loadState(param1:Object) : void
  329.       {
  330.          var _loc2_:int = !!param1 ? int(param1.selectedIndex) : 0;
  331.          if(_loc2_ == -1)
  332.          {
  333.             _loc2_ = initialSelectedIndex;
  334.          }
  335.          if(_loc2_ == -1)
  336.          {
  337.             _loc2_ = 0;
  338.          }
  339.          if(_loc2_ != _selectedIndex)
  340.          {
  341.             bInLoadState = true;
  342.             selectedIndex = _loc2_;
  343.             bInLoadState = false;
  344.          }
  345.       }
  346.       
  347.       protected function get contentWidth() : Number
  348.       {
  349.          var _loc1_:EdgeMetrics = viewMetricsAndPadding;
  350.          return unscaledWidth - _loc1_.left - _loc1_.right;
  351.       }
  352.       
  353.       override protected function commitProperties() : void
  354.       {
  355.          super.commitProperties();
  356.          if(historyManagementEnabledChanged)
  357.          {
  358.             if(historyManagementEnabled)
  359.             {
  360.                HistoryManager.register(this);
  361.             }
  362.             else
  363.             {
  364.                HistoryManager.unregister(this);
  365.             }
  366.             historyManagementEnabledChanged = false;
  367.          }
  368.          if(proposedSelectedIndex != -1)
  369.          {
  370.             commitSelectedIndex(proposedSelectedIndex);
  371.             proposedSelectedIndex = -1;
  372.          }
  373.          if(needToInstantiateSelectedChild)
  374.          {
  375.             instantiateSelectedChild();
  376.             needToInstantiateSelectedChild = false;
  377.          }
  378.          if(dispatchChangeEventPending)
  379.          {
  380.             dispatchChangeEvent(lastIndex,selectedIndex);
  381.             dispatchChangeEventPending = false;
  382.          }
  383.          if(firstTime)
  384.          {
  385.             firstTime = false;
  386.             addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler,false,0,true);
  387.             addEventListener(Event.REMOVED_FROM_STAGE,removedFromStageHandler,false,0,true);
  388.          }
  389.       }
  390.       
  391.       public function set resizeToContent(param1:Boolean) : void
  392.       {
  393.          if(param1 != _resizeToContent)
  394.          {
  395.             _resizeToContent = param1;
  396.             if(param1)
  397.             {
  398.                invalidateSize();
  399.             }
  400.          }
  401.       }
  402.       
  403.       override public function createComponentsFromDescriptors(param1:Boolean = true) : void
  404.       {
  405.          if(actualCreationPolicy == ContainerCreationPolicy.ALL)
  406.          {
  407.             super.createComponentsFromDescriptors();
  408.             return;
  409.          }
  410.          var _loc2_:int = numChildren;
  411.          var _loc3_:int = !!childDescriptors ? int(childDescriptors.length) : 0;
  412.          var _loc4_:int = 0;
  413.          while(_loc4_ < _loc3_)
  414.          {
  415.             createComponentFromDescriptor(childDescriptors[_loc4_],false);
  416.             _loc4_++;
  417.          }
  418.          mx_internal::numChildrenCreated = numChildren - _loc2_;
  419.          processedDescriptors = true;
  420.       }
  421.       
  422.       override protected function measure() : void
  423.       {
  424.          var _loc1_:Number = NaN;
  425.          var _loc2_:Number = NaN;
  426.          var _loc3_:Number = NaN;
  427.          var _loc4_:Number = NaN;
  428.          var _loc8_:Container = null;
  429.          super.measure();
  430.          _loc1_ = 0;
  431.          _loc2_ = 0;
  432.          _loc3_ = 0;
  433.          _loc4_ = 0;
  434.          if(Boolean(mx_internal::vsPreferredWidth) && !_resizeToContent)
  435.          {
  436.             measuredMinWidth = mx_internal::vsMinWidth;
  437.             measuredMinHeight = mx_internal::vsMinHeight;
  438.             measuredWidth = mx_internal::vsPreferredWidth;
  439.             measuredHeight = mx_internal::vsPreferredHeight;
  440.             return;
  441.          }
  442.          if(numChildren > 0 && selectedIndex != -1)
  443.          {
  444.             _loc8_ = Container(getChildAt(selectedIndex));
  445.             _loc1_ = _loc8_.minWidth;
  446.             _loc3_ = _loc8_.getExplicitOrMeasuredWidth();
  447.             _loc2_ = _loc8_.minHeight;
  448.             _loc4_ = _loc8_.getExplicitOrMeasuredHeight();
  449.          }
  450.          var _loc5_:EdgeMetrics = viewMetricsAndPadding;
  451.          var _loc6_:Number = _loc5_.left + _loc5_.right;
  452.          _loc1_ += _loc6_;
  453.          _loc3_ += _loc6_;
  454.          var _loc7_:Number = _loc5_.top + _loc5_.bottom;
  455.          _loc2_ += _loc7_;
  456.          _loc4_ += _loc7_;
  457.          measuredMinWidth = _loc1_;
  458.          measuredMinHeight = _loc2_;
  459.          measuredWidth = _loc3_;
  460.          measuredHeight = _loc4_;
  461.          if(Boolean(selectedChild) && Container(selectedChild).mx_internal::numChildrenCreated == -1)
  462.          {
  463.             return;
  464.          }
  465.          if(numChildren == 0)
  466.          {
  467.             return;
  468.          }
  469.          mx_internal::vsMinWidth = _loc1_;
  470.          mx_internal::vsMinHeight = _loc2_;
  471.          mx_internal::vsPreferredWidth = _loc3_;
  472.          mx_internal::vsPreferredHeight = _loc4_;
  473.       }
  474.       
  475.       override public function set verticalScrollPolicy(param1:String) : void
  476.       {
  477.       }
  478.       
  479.       public function set selectedIndex(param1:int) : void
  480.       {
  481.          if(param1 == selectedIndex)
  482.          {
  483.             return;
  484.          }
  485.          proposedSelectedIndex = param1;
  486.          invalidateProperties();
  487.          if(historyManagementEnabled && _selectedIndex != -1 && !bInLoadState)
  488.          {
  489.             bSaveState = true;
  490.          }
  491.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  492.       }
  493.       
  494.       override mx_internal function addOverlay(param1:uint, param2:RoundedRectangle = null) : void
  495.       {
  496.          if(overlayChild)
  497.          {
  498.             mx_internal::removeOverlay();
  499.          }
  500.          overlayChild = selectedChild;
  501.          if(!overlayChild)
  502.          {
  503.             return;
  504.          }
  505.          mx_internal::overlayColor = param1;
  506.          overlayTargetArea = param2;
  507.          if(Boolean(selectedChild) && selectedChild.mx_internal::numChildrenCreated == -1)
  508.          {
  509.             selectedChild.addEventListener(FlexEvent.INITIALIZE,initializeHandler);
  510.          }
  511.          else
  512.          {
  513.             initializeHandler(null);
  514.          }
  515.       }
  516.       
  517.       override public function set autoLayout(param1:Boolean) : void
  518.       {
  519.       }
  520.       
  521.       override public function get verticalScrollPolicy() : String
  522.       {
  523.          return ScrollPolicy.OFF;
  524.       }
  525.       
  526.       [Bindable("valueCommit")]
  527.       [Bindable("change")]
  528.       public function get selectedIndex() : int
  529.       {
  530.          return proposedSelectedIndex == -1 ? _selectedIndex : proposedSelectedIndex;
  531.       }
  532.       
  533.       private function childRemoveHandler(param1:ChildExistenceChangedEvent) : void
  534.       {
  535.          var _loc2_:DisplayObject = param1.relatedObject;
  536.          var _loc3_:int = getChildIndex(_loc2_);
  537.          if(_loc3_ > selectedIndex)
  538.          {
  539.             return;
  540.          }
  541.          var _loc4_:int = selectedIndex;
  542.          if(_loc3_ < _loc4_ || _loc4_ == numChildren - 1)
  543.          {
  544.             if(_loc4_ == 0)
  545.             {
  546.                selectedIndex = -1;
  547.                _selectedIndex = -1;
  548.             }
  549.             else
  550.             {
  551.                --selectedIndex;
  552.             }
  553.          }
  554.          else if(_loc3_ == _loc4_)
  555.          {
  556.             needToInstantiateSelectedChild = true;
  557.             invalidateProperties();
  558.          }
  559.       }
  560.       
  561.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  562.       {
  563.          var _loc8_:Container = null;
  564.          var _loc9_:Number = NaN;
  565.          var _loc10_:Number = NaN;
  566.          super.updateDisplayList(param1,param2);
  567.          var _loc3_:int = numChildren;
  568.          var _loc4_:Number = contentWidth;
  569.          var _loc5_:Number = contentHeight;
  570.          var _loc6_:Number = contentX;
  571.          var _loc7_:Number = contentY;
  572.          if(selectedIndex != -1)
  573.          {
  574.             _loc8_ = Container(getChildAt(selectedIndex));
  575.             _loc9_ = _loc4_;
  576.             _loc10_ = _loc5_;
  577.             if(!isNaN(_loc8_.percentWidth))
  578.             {
  579.                if(_loc9_ > _loc8_.maxWidth)
  580.                {
  581.                   _loc9_ = _loc8_.maxWidth;
  582.                }
  583.             }
  584.             else if(_loc9_ > _loc8_.explicitWidth)
  585.             {
  586.                _loc9_ = _loc8_.explicitWidth;
  587.             }
  588.             if(!isNaN(_loc8_.percentHeight))
  589.             {
  590.                if(_loc10_ > _loc8_.maxHeight)
  591.                {
  592.                   _loc10_ = _loc8_.maxHeight;
  593.                }
  594.             }
  595.             else if(_loc10_ > _loc8_.explicitHeight)
  596.             {
  597.                _loc10_ = _loc8_.explicitHeight;
  598.             }
  599.             if(_loc8_.width != _loc9_ || _loc8_.height != _loc10_)
  600.             {
  601.                _loc8_.setActualSize(_loc9_,_loc10_);
  602.             }
  603.             if(_loc8_.x != _loc6_ || _loc8_.y != _loc7_)
  604.             {
  605.                _loc8_.move(_loc6_,_loc7_);
  606.             }
  607.             _loc8_.visible = true;
  608.          }
  609.       }
  610.       
  611.       protected function get contentX() : Number
  612.       {
  613.          return getStyle("paddingLeft");
  614.       }
  615.    }
  616. }
  617.  
  618.